using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class spikeweed : Creation
{
    private Rigidbody2D myRigidbody;
    public float healthratio;
    public float CD;
    float CDtime;
    public GameObject thorn;
    Transform transform;
    public int skilltimes;
    int skilltimesnow;
    public float dietime = 30f;
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
        //enemyattack= attackobject.GetComponent<EnemyAttack> ();
        //face = enemyattack.face;
        transform = GetComponent<Transform>();
        face = GameObject.FindWithTag("Player").GetComponent<PlayerBasic>().face;
        if (face > 0) transform.localRotation = Quaternion.Euler(0, 180, 0);
        CDtime = CD;
        health = healthratio * GameObject.FindWithTag("Player").GetComponent<PlayerBasic>().health;
    }
    public override void TakeDamage(float damage)
    {
        health -= damage;
        if (health <= 0)
            Destroy(gameObject);
    }
    // Update is called once per frame
    void Update()
    {
        if (dietime < 0)
        {
            Destroy(gameObject);
        }
        dietime -= Time.deltaTime;
        if (myRigidbody.velocity.y >= 0)
        {
            if (CDtime > 0)
                    {
                        CDtime -= Time.deltaTime;
                    }
                    else
                    {
                        CDtime = CD;
                        Vector3 vector = transform.position;
                        skilltimesnow = skilltimesnow % skilltimes + 1;
                        vector.x -= face *skilltimesnow;
                        vector.y = -3.548f;
                        Instantiate(thorn, vector, Quaternion.identity);
                        vector.x += 2*face * skilltimesnow;
                        Instantiate(thorn, vector, Quaternion.identity);
                    }
        }
        
    }
}
